package com.aaa.service.impl;

import com.aaa.entity.QuestionSas;
import com.aaa.entity.TblQuestionSds;
import com.aaa.dao.TblQuestionSdsDao;
import com.aaa.service.TblQuestionSdsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 问题表(TblQuestionSds)表服务实现类
 *
 * @author makejava
 * @since 2022-07-15 20:48:06
 */
@Service("tblQuestionSdsService")
public class TblQuestionSdsServiceImpl implements TblQuestionSdsService {
    @Resource
    private TblQuestionSdsDao tblQuestionSdsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TblQuestionSds queryById(Integer id) {
        return this.tblQuestionSdsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tblQuestionSds 筛选条件
     * @param pageRequest    分页对象
     * @return 查询结果
     */
    @Override
    public Page<TblQuestionSds> queryByPage(TblQuestionSds tblQuestionSds, PageRequest pageRequest) {
        long total = this.tblQuestionSdsDao.count(tblQuestionSds);
        return new PageImpl<>(this.tblQuestionSdsDao.queryAllByLimit(tblQuestionSds, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tblQuestionSds 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(TblQuestionSds tblQuestionSds) {
        int insert = this.tblQuestionSdsDao.insert(tblQuestionSds);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    /**
     * 修改数据
     *
     * @param tblQuestionSds 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(TblQuestionSds tblQuestionSds) {
        int update = this.tblQuestionSdsDao.update(tblQuestionSds);
        if (update > 0) {
            return true;
        }
        return false;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String idList) {
        return this.tblQuestionSdsDao.deleteById(idList) > 0;
    }

    /**
     * @param TblQuestionSds
     * @return boolean
     * @create by: feng (zhaixing@163.com)
     * @description: 唯一性校验
     * @create time: 2022/7/15 17:18
     */
    @Override
    public boolean repetitionName(TblQuestionSds TblQuestionSds) {
        Integer integer = this.tblQuestionSdsDao.repetitionName(TblQuestionSds);
        if (integer == 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<TblQuestionSds> findAllQuestion() {
        return tblQuestionSdsDao.findAllQuestion();
    }
}
